package com.wl.tans;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

/**
 * @BelongsProject: rocketmq-demo
 * @BelongsPackage: cn.itsource._05_tran
 * @Author: Director
 * @CreateTime: 2022-09-14  16:53
 * @Description: TODO
 * @Version: 1.0
 */
// 事务消息的34567
public class MyTranListener implements TransactionListener {

    // 执行本地事务代码的方法
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {
        System.out.println("执行了本地事务成功！" + o);
        return LocalTransactionState.COMMIT_MESSAGE;
    }

    //  检查本地事务是否成功的方法
    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        System.out.println("检查本地事务，本地事务执行失败！");
        return LocalTransactionState.ROLLBACK_MESSAGE;
    }
}
